package pw.canyingisme.plugin;

//import com.comphenix.protocol.ProtocolLibrary;
//import com.comphenix.protocol.ProtocolManager;
//import com.comphenix.protocol.events.ListenerOptions;
//import com.comphenix.protocol.events.ListenerPriority;
//import com.comphenix.protocol.events.PacketAdapter;
//import com.comphenix.protocol.injector.GamePhase;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import pw.canyingisme.plugin.action.ActionManager;
import pw.canyingisme.plugin.occupation.OccupationEffectTask;
import pw.canyingisme.plugin.occupation.OccupationEventListener;
import pw.canyingisme.plugin.occupation.OccupationPlaceholder;
import pw.canyingisme.plugin.console.Console;
import pw.canyingisme.plugin.myConsole.Consoleself;
import pw.canyingisme.plugin.api.Bukkit;
import pw.canyingisme.plugin.config.ConfigLoader;
import pw.canyingisme.plugin.occupation.OccupationCommand;
public final class ShadowOccupation extends JavaPlugin implements Listener {
    private final OccupationEffectTask effectTask = new OccupationEffectTask();
    //private static ProtocolManager pm;
    @Override
    public void onEnable() {
        // Plugin startup logic
        Console.pluginEnableMessage(this);
        Consoleself.outPut("ShadowOccupation","插件被载入");
        Consoleself.outPut("ShadowOccupation","ShadowOccupation By:CanYingisme");
        Consoleself.outPut("ShadowOccupation","运行在MC"+ Bukkit.getVersion());
        if(!ConfigLoader.loadOccupationConfig(this)){
            Consoleself.outPut("ShadowOccupation","配置文件载入失败");
        }else{
            Consoleself.outPut("ShadowOccupation","配置文件载入成功");
        }
        if(!ConfigLoader.loadPlayerOccupationConfig(this)){
            Consoleself.outPut("ShadowOccupation","玩家配置文件载入失败");
        }else {
            Consoleself.outPut("ShadowOccupation","玩家配置文件载入成功");
        }
        effectTask.runTaskTimerAsynchronously(this, 0, 20);
        Consoleself.outPut("ShadowOccupation","药水线程启动成功");
        Bukkit.registerListener(this,new OccupationEventListener());
        Consoleself.outPut("ShadowOccupation","注册监听器成功");
        if(ConfigLoader.LoadActionConfig(this) && ActionManager.init()){
            Consoleself.outPut("ShadowOccupation","事件动作解释器载入成功");
        }else {
            Consoleself.outPut("ShadowOccupation","事件动作解释器载入失败");
        }
        //pm= ProtocolLibrary.getProtocolManager();
        //pm.addPacketListener(new PacketAdapter(PacketAdapter.params().plugin(this).clientSide().serverSide().listenerPriority(ListenerPriority.NORMAL).gamePhase(GamePhase.BOTH).optionAsync().options(ListenerOptions.SKIP_PLUGIN_VERIFIER)) {});
        Consoleself.outPut("ShadowOccupation","初始化数据包类成功");
        if(org.bukkit.Bukkit.getPluginManager().getPlugin("PlaceholderAPI")!=null){
            if(new OccupationPlaceholder().register()){
                Consoleself.outPut("ShadowOccupation","Hook PlaceholderAPI成功");
            }else{
                Consoleself.outPut("ShadowOccupation","Hook PlaceholderAPI失败");
            }
        }else {
            Consoleself.outPut("ShadowOccupation","服务端未安装PlaceholderAPI");
            return;
        }
    }
    @Override
    public void onDisable() {
        // Plugin shutdown logic
        Console.pluginDisableMessage(this);
    }
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        return OccupationCommand.onCommand(sender,cmd,label,args);
    }
}
